package demo3;

public class test {
    public static void main(String[] args) {
        Node tom = new Node("tom");
        Node cate = new Node("cate");
        Node jack = new Node("jack");
        tom.next=cate;
        cate.next=jack;
        cate.pre=tom;
        jack.pre=cate;

        Node first = tom;
        Node last = jack;
        while(true){
            if(first==null){
                break;
            }
            System.out.println(first);
            first=first.next;
        }

        while(true){
            if(last==null){
                break;
            }
            System.out.println(last);
            last=last.pre;
        }
    }
}

class Node{
    public Object item;
    public Node next;
    public Node pre;
    public Node(Object name){
        this.item=name;
    }

    public String toString() {
        return "this item: "+item;
    }
}
